import { _decorator, Component, director, Label, Node, ProgressBar } from 'cc';
import { AudioMgr } from './utils/AudioMgr';
import { UserInfo } from './UserInfo';
const { ccclass, property } = _decorator;

@ccclass('LoadDycxy')
export class LoadDycxy extends Component {
    @property(ProgressBar)
    progressBar: ProgressBar = null;

    @property(Label)
    progressLabel: Label = null;


    onLoad() {
        this.loadTargetScene();
    }

    protected start(): void {
        if (UserInfo.isAudioBgm) {
            AudioMgr.ins.play("audio/bgm");
        }
        else{
            AudioMgr.ins.stop();
        }
    }

    loadTargetScene() {
        director.preloadScene("dycxy", (completedCount, totalCount, item) => {
            let progress = completedCount / totalCount;
            this.progressBar.progress = progress;
            this.progressLabel.string = `${Math.floor(progress * 100)}%`;
        }, (error) => {
            if (error) {
                console.log(error);
                return;
            }

            setTimeout(() => {
            director.loadScene("dycxy");
                
            }, 3000);
        });
    }
}


